<?php

/**
 * @copyright: ©2024 永州微聚商网络科技有限公司
 * @link: https://www.weijuyunke.com
 */

namespace app\common\service;

use think\facade\Log;
use app\admin\model\SystemConfig;
use app\admin\service\TriggerService;

class AgentApiService
{

    // private $url = 'http://digital.weijuyunke.cn';
    protected $url = '';

    protected $appid;

    protected $appsecret;

    protected $token;

    protected $expires_in;

    /**
     * 架构函数
     *
     * @access public
     */
    public function __construct()
    {
        $set = sysconfig('account');
        $this->url = empty($set['agent_url']) ? '' : $set['agent_url'];
        $this->appid = empty($set['account_appid']) ? '' : $set['account_appid'];
        $this->appsecret = empty($set['account_appsecret']) ? '' : $set['account_appsecret'];
        $this->token = empty($set['account_token']) ? '' : $set['account_token'];
        $this->expires_in = empty($set['account_expires_in']) ? '' : $set['account_expires_in'];
    }

    public function getToken()
    {
        if (empty($this->appid) || empty($this->appsecret)) {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => '请检查后台账号设置'
            );
        }
        if ($this->expires_in > time()) {
            return array(
                'code' => 1,
                'data' => $this->token,
                'msg' => 'success'
            );
        } else {
            return $this->login();
        }
    }

    public function test()
    {
        $url = $this->url . '/openApi/index/test';

        $ret = $this->httpGet($url, []);

        return $ret;
    }

    public function login()
    {
        if (empty($this->appid) || empty($this->appsecret)) {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => '请检查后台账号设置'
            );
        }

        $url = $this->url . '/openApi/user/login';

        $body = array(
            'appid' => $this->appid,
            'appsecret' => $this->appsecret
        );

        $result = json_decode($this->apiPost($url, [], $body), true);

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {

            $token = $result['data']['token'];
            $expires_in = strtotime("+2 hour", time());

            SystemConfig::where([
                'name' => 'account_token'
            ])->update([
                'value' => $token
            ]);

            SystemConfig::where([
                'name' => 'account_expires_in'
            ])->update([
                'value' => $result['data']['expire_time']
            ]);

            TriggerService::updateSysconfig();

            return array(
                'code' => 1,
                'data' => $token,
                'msg' => 'success'
            );
        } else {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
    }

    public function info()
    {
        $url = $this->url . '/openApi/user/info';

        $rtn = $this->getToken();


        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, []);

        $result = json_decode($ret, true);

        Log::write("ApiService info " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'ret' => $ret
            )), 'info');

        if (isset($result['errno']) && $result['errno'] == 0) {
            return array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
    }

    public function log($params)
    {
        $url = $this->url . '/openApi/account/log';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'page' => $params['page'],
            'psize' => $params['psize']
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService log " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        if (isset($result['errno']) && $result['errno'] == 0) {
            return array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
    }


    public function ttsUpload($params)
    {
        $url = $this->url . '/openApi/voice/ttsUpload';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );
        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";
        $body = [
            'name' => $params['name'],
            'voice_urls' => $params['voice_urls'],
            'sex' => $params['sex'],
            'callbackUrl' => $callbackUrl
        ];
        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService ttsUpload " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function ttsContinue($params)
    {
        $url = $this->url . '/openApi/voice/ttsContinue';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $params['id'],
            'voice_urls' => $params['voice_urls']
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService ttsContinue " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function ttsVoice($params)
    {
        $url = $this->url . '/openApi/voice/ttsVoice';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $params['id'],
            'text' => $params['text'],
            'speedRatio' => $params['speedRatio']
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService ttsVoice " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {

            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function ttsSsml($params)
    {
        $url = $this->url . '/openApi/voice/ttsSsml';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $params['id'],
            'text' => $params['text'],
            'speedRatio' => $params['speedRatio']
        ];


        $body['customer_alioss_access_key_id'] = sysconfig('upload', 'alioss_access_key_id');
        $body['customer_alioss_access_key_secret'] = sysconfig('upload', 'alioss_access_key_secret');
        $body['customer_alioss_endpoint'] = sysconfig('upload', 'alioss_endpoint');
        $body['customer_alioss_bucket'] = sysconfig('upload', 'alioss_bucket');
        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService ttsSsml " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function voiceTraining($params)
    {
        $url = $this->url . '/openApi/composite/voiceTraining';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";

        $body = [
            'name' => $params['name'],
            'voice_urls' => $params['voice_urls'],
            'mode' => 2,
            'callbackUrl' => $callbackUrl
        ];

        $ret = $this->apiPost($url, $header, $body);
        $result = json_decode($ret, true);

        Log::write("ApiService voiceTraining " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function voiceList()
    {
        $url = $this->url . '/openApi/voice/voiceList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [];

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService voiceList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {

            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function avatarList()
    {
        $url = $this->url . '/openApi/avatar/videoList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function avatarAdd($params)
    {
        $url = $this->url . '/openApi/avatar/avatarAdd';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url']
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarAdd " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function avatarUpload($params)
    {
        $url = $this->url . '/openApi/avatar/videoUpload';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'name' => $params['name']
        ];

        if (!empty($params['image_url'])) {
            $body['image_url'] = $params['image_url'];
        }

        if (!empty($params['video_url'])) {
            $body['video_url'] = $params['video_url'];
        }

        if (!empty($params['video_backgroud_image'])) {
            $body['video_backgroud_image'] = $params['video_backgroud_image'];
        }

        if (!empty($params['video_backgroud_color'])) {
            $body['video_backgroud_color'] = $params['video_backgroud_color'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarUpload " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function avatarStartTraining($params)
    {
        $url = $this->url . '/openApi/avatar/startTraining';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url'],
            'callbackUrl' => $callbackUrl
        ];
        if (isset($params['_id'])) {
            $body['_id'] = $params['_id'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarStartTraining " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function avatarDetail($id)
    {
        $url = $this->url . '/openApi/avatar/avatarStatus';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $id
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarDetail " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function CompositeAvatarDetail($id)
    {
        $url = $this->url . '/openApi/Composite/avatarStatus';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $id
        ];

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService CompositeAvatarDetail " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function sendTts($params)
    {
        $url = $this->url . '/openApi/composite/sendTts';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );
        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";
        $body = $params;

        $body['callbackUrl'] = $callbackUrl;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService sendTts " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function generate($params)
    {
        $url = $this->url . '/openApi/video/generate';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = $params;

        $body['callbackUrl'] = $callbackUrl;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService generate " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function videoList()
    {
        $url = $this->url . '/openApi/video/videoList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [];

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService videoList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function timbreList()
    {
        $url = $this->url . '/openApi/voice/timbreList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, []);

        $result = json_decode($ret, true);

        Log::write("ApiService timbreList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function soundDetail($id)
    {
        $url = $this->url . '/openApi/composite/soundStatus';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'id' => $id
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService soundDetail " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function compositeAvatarAdd($params)
    {
        $url = $this->url . '/openApi/composite/avatarAdd';

        $rtn = $this->getToken();


        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";

        $body = [
            'name' => $params['name'],
            'url' => $params['url'],
            'callbackUrl' => $callbackUrl
        ];

        if (!empty($params['back_size'])) {
            $body['back_size'] = $params['back_size'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService compositeAvatarAdd " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function compositeAvatarList()
    {
        $url = $this->url . '/openApi/composite/avatarList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, []);

        $result = json_decode($ret, true);

        Log::write("ApiService compositeAvatarList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function compositeSoundAdd($params)
    {
        $url = $this->url . '/openApi/composite/soundAdd';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );
        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";

        $body = [
            'name' => $params['name'],
            'url' => $params['url'],
            'callbackUrl' => $callbackUrl,
        ];

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService compositeSoundAdd " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function submitVideo($params)
    {
        $url = $this->url . '/openApi/composite/generate';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";

        $body = [
            'name' => $params['name'],
            'image_id' => $params['image_id'],
            'sound_id' => $params['sound_id'],
            'callbackUrl' => $callbackUrl
        ];

        if (!empty($params['width'])) {
            $body['width'] = $params['width'];
        }

        if (!empty($params['height'])) {
            $body['height'] = $params['height'];
        }

        if (!empty($params['combination'])) {
            $body['combination'] = $params['combination'];
        }

        if (!empty($params['caption_json'])) {
            $body['caption_json'] = $params['caption_json'];
        }


        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService submitVideo " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function synthesisAvatarAdd($params)
    {
        $url = $this->url . '/openApi/synthesis/avatarTraining';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url'],
            'callbackUrl' => $callbackUrl
        ];

        if (!empty($params['line_type'])) {
            $body['line_type'] = $params['line_type'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService synthesisAvatarAdd " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    function apiPost($url, $header, $data = NULL)
    {
        $request = Request();
        $domain = $request->host();

        $headers = array(
            'Content-Type: application/json; charset=utf-8'
        );
        if (!empty($header)) {
            $headers = array_merge($headers, $header);
        }

        $send_data = array(
            'appid' => sysconfig('account', 'account_appid'),
            'appsecret' => sysconfig('account', 'account_appsecret'),
            'domain' => $domain
        );

        if (!empty($data)) {

            if (!is_array($data)) {
                $data = $data->toArray();
            }

            $send_data = array_merge($send_data, $data);
        }

        $userAgent = !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';

        // 模拟提交数据函数
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $userAgent); // 模拟用户使用的浏览器
        curl_setopt($curl, CURLOPT_POST, true); // 发送一个常规的Post请求
        curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($send_data)); // Post提交的数据包
        curl_setopt($curl, CURLOPT_TIMEOUT, 600); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // 获取的信息以文件流的形式返回
        curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // 类型为json
        $result = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            echo 'Error POST' . curl_error($curl);
        }
        curl_close($curl); // 关键CURL会话
        return $result; // 返回数据
    }

    function httpGet($url, $header = [])
    {
        $request = Request();
        $domain = $request->host();

        $headers = array(
            'Content-Type: application/json; charset=utf-8'
        );
        if (!empty($header)) {
            $headers = array_merge($headers, $header);
        }

        // 初始化
        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        // 执行后不直接打印出来
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false); // 显示返回的Header区域内容
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // 类型为json
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        // 不从证书中检查SSL加密算法是否存在
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

        // 执行并获取HTML文档内容
        $output = curl_exec($ch);

        // 释放curl句柄
        curl_close($ch);

        return $output;
    }

    public function aiCreatePoints($type)
    {
        $url = $this->url . '/openApi/AiCreate/aiCreatePoints';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );
        if ($type == 16) {
            $data['type'] = 2;
        } else {
            $data['type'] = 1;
        }

        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);

        Log::write("ApiService aiCreatePoints " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'ret' => $ret
            )), 'info');

        if (isset($result['errno']) && $result['errno'] == 0) {
            return array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
    }

    public function aiCreateTitle($data)
    {
        $url = $this->url . '/openApi/AiCreate/aiTitleAdd';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            return array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            return array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
    }

    public function generateTwo($params)
    {
        $url = $this->url . '/openApi/video/generateTwo';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = [
            'title' => $params['name'],
            'image_id' => $params['image_id'],
            'sound_id' => $params['sound_id'],
            'callbackUrl' => $callbackUrl
        ];
        $body['customer_alioss_access_key_id'] = sysconfig('upload', 'alioss_access_key_id');
        $body['customer_alioss_access_key_secret'] = sysconfig('upload', 'alioss_access_key_secret');
        $body['customer_alioss_endpoint'] = sysconfig('upload', 'alioss_endpoint');
        $body['customer_alioss_bucket'] = sysconfig('upload', 'alioss_bucket');
        if (!empty($params['width'])) {
            $body['width'] = $params['width'];
        }

        if (!empty($params['height'])) {
            $body['height'] = $params['height'];
        }

        if (!empty($params['combination'])) {
            $body['combination'] = $params['combination'];
        }

        if (!empty($params['caption_json'])) {
            $body['caption_json'] = $params['caption_json'];
        }

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService generate " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function fourGenerate($params)
    {
        $url = $this->url . '/openApi/video/fourGenerate';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = $params;

        $body['callbackUrl'] = $callbackUrl;

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);

        Log::write("ApiService generate " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function StartTrainingTow($params)
    {
        $url = $this->url . '/openApi/avatar/towTraining';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url'],
            'callbackUrl' => $callbackUrl,
        ];
        if (isset($params['is_avatar'])) {
            $body['is_avatar'] = $params['is_avatar'];
        }
        if (isset($params['_id'])) {
            $body['_id'] = $params['_id'];
        }

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);


        Log::write("ApiService avatarStartTraining " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xunfeiTrainText()
    {
        $url = $this->url . '/openApi/Voice/trainText';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, []);


        $result = json_decode($ret, true);


        Log::write("ApiService xunfeiTrainText " . json_encode(array(
                'url' => $url,
                'header' => $header,

                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function voiceTaskAdd($taskAddData)
    {

        $url = $this->url . '/openApi/Voice/voiceTaskAdd';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";
        $body = $taskAddData;
        $body['callbackUrl'] = $callbackUrl;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);
        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function voiceClone($params)
    {
        $url = $this->url . '/openApi/Voice/voiceClone';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/compositeCallback";
        $body = $params;

        $body['callbackUrl'] = $callbackUrl;

        $ret = $this->apiPost($url, $header, $body);
        $result = json_decode($ret, true);

        Log::write("ApiService voiceClone " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function avatarClone($params)
    {
        $url = $this->url . '/openApi/avatar/avatarClone';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";

        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url'],
            'way' => $params['way'],
            'callbackUrl' => $callbackUrl
        ];
        if (isset($params['_id'])) {
            $body['_id'] = $params['_id'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarStartTraining " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function uploadAvatar($params)
    {
        $url = $this->url . '/openApi/avatar/uploadAvatar';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $request = Request();
        $domain = $request->host();
        $callbackUrl = "http://" . $domain . "/mobile/callback/synthesisCallback";
        $body = [
            'name' => $params['name'],
            'video_url' => $params['video_url'],
            'callbackUrl' => $callbackUrl
        ];
        if (isset($params['_id'])) {
            $body['_id'] = $params['_id'];
        }

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService avatarStartTraining " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'data' => $result['data'],
                'msg' => 'success'
            );
        } else {
            $return = array(
                'code' => 0,
                'data' => [],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function releaseKuaishouVideo($data)
    {
        $url = $this->url . '/openApi/externalAccount/releaseKuaishouVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function releaseXiaohongshuVideo($data)
    {
        $url = $this->url . '/openApi/externalAccount/releaseXiaohongshuVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        //  $data['cookie'] = urlencode( $data['cookie']);


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function releaseShipinghaoVideo($data)
    {
        $url = $this->url . '/openApi/externalAccount/releaseShipinghaoVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function releaseDouyinVideo($data)
    {
        $url = $this->url . '/openApi/externalAccount/releaseDouyinVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function douyinQrcode($param){

        $url = $this->url . '/openApi/externalAccount/douyinQrcode';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $body['proxy'] = $param['proxy'];
        $body['cookie'] = $param['cookie'];

        $ret = $this->apiPost($url, $header, $body);



        $result = json_decode($ret, true);

        if (isset($result['code']) && $result['code'] == 200) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function douyinAuthorizeUserInfo($data)
    {

        $url = $this->url . '/openApi/externalAccount/douyinAuthorizeUserInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'cookie' => $data['cookie'],
        ];
        $ret = $this->apiPost($url, $header, $body);
        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function shipinghaoQrcode($proxy)
    {
        $url = $this->url . '/openApi/externalAccount/shipinghaoQrcode';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body['proxy'] = $proxy;
        $ret = $this->apiPost($url, $header, $body);;


        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function shipinghaoeQrcodeCheck($data)
    {

        $url = $this->url . '/openApi/externalAccount/shipinghaoeQrcodeCheck';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        //  $body['proxy'] = $data['proxy'];
        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xiaohongshuQrcode()
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuQrcode';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, []);


        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xiaohongshuAuthorizeUserInfo($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuAuthorizeUserInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function douyinQrcodeCheck($data){

        $url = $this->url . '/openApi/externalAccount/douyinQrcodeCheck';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);

        if (isset($result['code']) && $result['code'] == 200) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function douyinSendSms($data){

        $url = $this->url . '/openApi/externalAccount/douyinSendSms';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $body = [
            'encrypt_uid' => $data['encrypt_uid'],
            'token' => $data['token'],
            'cookie' => $data['cookie'],
        ];

        $ret = $this->apiPost($url, $header, $body);
        ;

        $result = json_decode($ret, true);



        if (isset($result['code']) && $result['code'] == 200) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function douyinVerifySms($data){
        $url = $this->url . '/openApi/externalAccount/douyinVerifySms';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $body = [
            'encrypt_uid' => $data['encrypt_uid'],
            'code' => $data['code'],
            'token' => $data['token'],
            'cookie' => $data['cookie'],
        ];
        $ret = $this->apiPost($url, $header, $body);
        $result = json_decode($ret, true);
        if (isset($result['code']) && $result['code'] == 200) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
            if (isset($result['data']['data']['error_code']) && $result['data']['data']['error_code'] ){
                $return = array(
                    'code' => 0,
                    'msg' => isset($result['data']['data']['description']) ? $result['data']['data']['description'] : ''
                );
            }
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }
        return $return;
    }


    public function douyinCookie($data)
    {

        $url = $this->url . '/openApi/externalAccount/douyinCookie';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body['proxy'] = $data['proxy'];
        $body['cookie'] = $data['cookie'];
        $body['token'] = $data['token'];
        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function douyinUserInfo($data)
    {

        $url = $this->url . '/openApi/externalAccount/douyinUserInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = [
            'cookie' => $data['cookie'],
        ];
        $ret = $this->apiPost($url, $header, $body);
        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function xiaohongshuQrcodeCheck($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuQrcodeCheck';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body['cookie'] = $data['cookie'];
        $body['qr_id'] = $data['qr_id'];
        $body['code'] = $data['code'];

        $ret = $this->apiPost($url, $header, $body);


        $result = json_decode($ret, true);


        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function xiaohongshuUserInfo($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuUserInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        // $body['cookie'] = urlencode($data['cookie']);

        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function XiaohongshuVideoInfo($data)
    {
        $url = $this->url . '/openApi/externalAccount/XiaohongshuVideoInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        //  $data['cookie'] = urlencode( $data['cookie']);
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;

    }


    public function douyinVideoInfo($data)
    {
        $url = $this->url . '/openApi/externalAccount/douyinVideoInfo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function uploadShipinghaoVideo($data)
    {
        $url = $this->url . '/openApi/externalAccount/uploadShipinghaoVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function shipinghaoVideoUploadStatus($data)
    {
        $url = $this->url . '/openApi/externalAccount/shipinghaoVideoUploadStatus';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function xiaohongshuTopic($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuTopic';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        //$data['cookie'] = urlencode($data['cookie']);

        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function douyinCommentList($data)
    {
        $url = $this->url . '/openApi/externalAccount/douyinCommentList';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function douyinLastCommentList($data)
    {
        $url = $this->url . '/openApi/externalAccount/douyinLastCommentList';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xiaohongshuCommentList($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuCommentList';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        // $body['cookie'] = urlencode($data['cookie']);
        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xiaohongshuLastCommentList($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuLastCommentList';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }    // $body['cookie'] = urlencode($data['cookie']);
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function kuaishouVideoComment($data)
    {
        $url = $this->url . '/openApi/externalAccount/kuaishouVideoComment';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }   //  $body['cookie'] = urlencode($data['cookie']);
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );


        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function douyinComment($data)
    {
        $url = $this->url . '/openApi/externalAccount/douyinComment';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function xiaohongshuComment($data)
    {
        $url = $this->url . '/openApi/externalAccount/xiaohongshuComment';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        //  $data['cookie'] = urlencode($data['cookie']);
        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function getVideoCopywriting($data)
    {
        $url = $this->url . '/openApi/Aicreate/getVideoCopywriting';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        // $data['cookie'] = urlencode($data['cookie']);
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function selectVideoCopywriting($data)
    {
        $url = $this->url . '/openApi/Aicreate/selectVideoCopywriting';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function doBaoVideoCopywriting($data)
    {
        $url = $this->url . '/openApi/Aicreate/doBaoVideoCopywriting';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function getComposition($data)
    {
        $url = $this->url . '/openApi/Aicreate/getComposition';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function HomepageCount($data)
    {
        $url = $this->url . '/openApi/Aicreate/HomepageCount';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function videoAnalysis($data)
    {
        $url = $this->url . '/openApi/Aicreate/videoAnalysis';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }

        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);


        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function getHotspot()
    {
        $url = $this->url . '/openApi/Aicreate/getHotspot';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, []);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function localVideo($data)
    {
        $url = $this->url . '/openApi/Aicreate/localVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function platformCopywriting($data)
    {
        $url = $this->url . '/openApi/Aicreate/platformCopywriting';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function createMediaJobs($data = [])
    {
        $url = $this->url . '/openApi/Aicreate/createMediaJobs';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function describeMediaJob($data)
    {
        $url = $this->url . '/openApi/Aicreate/describeMediaJob';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }


    public function wenshengPicture($data)
    {
        $url = $this->url . '/openApi/Intelligence/wenshengPicture';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function replacement($data)
    {
        $url = $this->url . '/openApi/Intelligence/replacement';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function replacementSelect($data)
    {
        $url = $this->url . '/openApi/Intelligence/replacementSelect';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }

        return $return;
    }

    public function oldImageRepair($data)
    {
        $url = $this->url . '/openApi/Intelligence/oldImageRepair';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function faceTransplant($data)
    {
        $url = $this->url . '/openApi/Intelligence/faceTransplant';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function changeHair($data)
    {
        $url = $this->url . '/openApi/Intelligence/changeHair';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function imgEdit($data)
    {

        $url = $this->url . '/openApi/Intelligence/imgEdit';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['code'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function highDefinition($data)
    {
        $url = $this->url . '/openApi/Intelligence/highDefinition';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function separateAudio($data)
    {

        $url = $this->url . '/openApi/Intelligence/separateAudio';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    /**
     * @return string
     */
    public function separateAudioResult($data)
    {
        $url = $this->url . '/openApi/Intelligence/separateAudioResult';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function imgGenerateVideo($data)
    {
        $url = $this->url . '/openApi/Intelligence/imgGenerateVideo';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function imgGenerateVideoSelect($data)
    {
        $url = $this->url . '/openApi/Intelligence/imgGenerateVideoSelect';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['massge']) ? $result['message'] : ''
            );
        }
        return $return;
    }

    public function voiceDetail($data)
    {
        $url = $this->url . '/openApi/voice/voiceDetail';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = $data;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService voiceList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function awsDetail($data)
    {
        $url = $this->url . '/openApi/video/awsDetail';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = $data;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService voiceList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function voiceListUpdate($data)
    {
        $url = $this->url . '/openApi/voice/voiceList';

        $rtn = $this->getToken();

        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];

        $header = array(
            'Authorization: ' . $token
        );

        $body = $data;

        $ret = $this->apiPost($url, $header, $body);

        $result = json_decode($ret, true);

        Log::write("ApiService voiceList " . json_encode(array(
                'url' => $url,
                'header' => $header,
                'body' => $body,
                'ret' => $ret
            )), 'info');

        $return = [];

        if (isset($result['code']) && $result['code'] == 200) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => 0,
                'msg' => isset($result['msg']) ? $result['msg'] : ''
            );
        }

        return $return;
    }

    public function handheldProduct($data)
    {
        $url = $this->url . '/openApi/Intelligence/handheldProduct';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );

        $ret = $this->apiPost($url, $header, $data);
        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }
    public function handheldSelect($data)
    {
        $url = $this->url . '/openApi/Intelligence/handheldSelect';
        $rtn = $this->getToken();
        if (!isset($rtn['code']) || $rtn['code'] != 1) {
            return array(
                'code' => 0,
                'msg' => $rtn['msg']
            );
        }
        $token = $rtn['data'];
        $header = array(
            'Authorization: ' . $token
        );
        $ret = $this->apiPost($url, $header, $data);

        $result = json_decode($ret, true);
        if (isset($result['errno']) && $result['errno'] == 0) {
            $return = array(
                'code' => 1,
                'msg' => 'success',
                'data' => $result['data']
            );
        } else {
            $return = array(
                'code' => $result['errno'],
                'msg' => isset($result['message']) ? $result['message'] : ''
            );
        }
        return $return;
    }
}